package com.aipolice.web;


import com.aipolice.pojo.Admin;
import com.aipolice.service.AdminService;
import com.aipolice.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.util.HtmlUtils;

import javax.servlet.http.HttpSession;

@RestController
public class AdminController {

    @Autowired
    AdminService adminService;
    @PostMapping("/forelogin")
    public Object login(Admin userParam, HttpSession session) {
        String name =  userParam.getUsername();
        System.out.println(userParam.getUsername());
//        防止恶意注册
//        name = HtmlUtils.htmlEscape(name);

        Admin user =adminService.get(name,userParam.getPassword());
        if(null==user){
            String message ="账号密码错误";
            return Result.fail(message);
        }
        else{
            session.setAttribute("user", user);
            return Result.success();
        }
    }

}
